ECE 4160 Fast Robots

Raphael Fortuna


Lab reports made by Raphael Fortuna @ rafCodes Hosted on GitHub Pages — Theme by mattgraham

Home

Lab 6: Closed Loop Control (PID)

Summary

In this lab, I added a system for collected and sending debug data for ToF, IMU, and motor data. I created a P controller to control the car’s distance to a wall with the ToF sensor and tuned it so that it would stop ~1 foot in front of a wall.

Prelab

I first added a new UUID for the motor data being sent from the robot and made sure it was being received and processed by my laptop. I also added data collection functions to the sensor functions to automatically collect data whenever the sensor was running and returned data.

The data was stored on the car using the Arduino String library with strict limitations on char sizes being reserved and how many values were reserved for each of the three messages being sent to avoid any memory holes in the heap or the heap and stack colliding. I also had it blink the LED once it had was out of space to collect data.

Although I used the String library for this lab, I will be swapping to arrays in future labs due to size constraints to store more data per run. Below is the current code used for sending, saving, and processing the IMU, ToF, and motor data with one example for each since they are all very similar in structure.

Position Control Task

This task involves stopping .304 m from the wall and starting 2-4 meters from the wall – the value of the ToF sensors, so the range of error value is ~700 mm to ~304 mm. With the default settings, the ToF sensors were updating the motors once a second, so I changed the intermeasurement period to 10 milliseconds.

I used a P controller and used 0.03 for kp. I also added a function to change the kp value via Bluetooth and saved the collected data as .npy files. I made sure to keep collecting data while waiting for the ToF to return data and ran the PID and graphed the collected data with 1814 IMU data points for roll and pitch, 56 ToF data points for the single sensor being used, and 114 data points for the motor inputs. I only used P here since the car was able to stop far enough from the wall.

I converted the speed from the PID controller using the below function.

Using the collected data, the maximum speed achieved was a jolt of 7.3 m/s, with an average speed of .73 m/s during the majority of the car’s movement period.

ToF vs time graph with a gradual decrease

IMU vs time graph with some noise at the beginning until stabiling near the end

Motor vs time graph with a gradual decrease in speed

Here is the video whose data is shown above.

The car was able to stop but had a little bit of overshoot that led to it backing up to get to the 304 mm distance that corresponded to 1 foot. After going through the data and code, I have narrowed this down to filtering the ToF sensor before saving it to be sent, but not when the sensor data is gathered, I will update it to filter when it first gathered.

Here are the two other trials.